/**
 * @param {number[]} nums
 */
export var Solution = function (nums) {
  this.numsMap = new Map()
  for (let i = 0; i < nums.length; i++) {
    if (!this.numsMap.has(nums[i])) {
      this.numsMap.set(nums[i], [])
    }
    this.numsMap.get(nums[i]).push(i)
  }
}

/**
 * @param {number} target
 * @return {number}
 */
Solution.prototype.pick = function (target) {
  if (!this.numsMap.has(target)) return -1
  const indexList = this.numsMap.get(target)
  const index = Math.floor(Math.random() * indexList.length)
  return indexList[index]
}

/**
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(nums)
 * var param_1 = obj.pick(target)
 */
